<?php
//Product Class

class Order
{
	public $id;				//Order ID
    public $user;			//User ID
    public $Products; // Array containing the id of the products
	public $Quantity; // Array containing the quantity of each ordered product
	public $price;
	public $date;
	public $totalQty; // Number of all the items ordered
	public $total;
	
	public function __construct($db,$id) 	//Just like the other classes, we choosed to use __construct function to retrieve products rather then building one.
    {										// The product creation function is a regular function
		$reponse = $db->query('SELECT * FROM jktrade_orders WHERE ord_id='.$id.'');
		$data = $reponse->fetch();
		
		$this->id = $data['ord_id'];
		$this->user = $data['ord_user'];	
		$this->Products = unserialize($data['ord_products']);
		$this->Quantity = unserialize($data['ord_quantity']);
		$this->price = $data['ord_price'];
		$this->order_date = $data['ord_date'];
	}
	
	
	public function getTotalQty()
    {
		foreach($this->Quantity as $nb_item)
		{
			$this->totalQty += $nb_item;
		}
		
        return $this->totalQty ;
    }
}
?>